namespace Pic.Web.Controllers
{
    using System;
    using System.Collections;
    using Castle.MonoRail.Framework;
    using Castle.MonoRail.Framework.Helpers;
    using NHibernate.Expression;
    using Pic.Model;
    using Castle.MonoRail.Framework.Adapters;
    using NHibernate;
    using Pic.Web.Filters;

    [Layout("default"), Rescue("generalerror")]
    [Filter(ExecuteEnum.BeforeAction, typeof(MemberFilter))]
    public class PManageController : SmartDispatcherController
    {
        public void my(string page)
        {
            DetachedCriteria xICriteria = DetachedCriteria.For(typeof(Pic_Album));
            xICriteria.AddOrder(Order.Desc("Pic_AlbumID"));
            xICriteria.Add(Expression.Eq("Status", (byte)1));
            xICriteria.Add(Expression.Eq("Pic_Member", (Pic_Member)Session["Member"]));
            IList dataSource = Pic_Album.FindAll(xICriteria);
            if (string.IsNullOrEmpty(page)) page = "1";

            PropertyBag["Albums"] = PaginationHelper.CreatePagination(this, dataSource, 12);
            PropertyBag["cPage"] = page;


        }

        public void myFav(string page) { 
            IList FavdataSource = Pic_Favorite.FindAll(Order.Desc("Pic_FavoriteID"), Expression.Eq("Pic_Member", (Pic_Member)Session["Member"]));

            if (string.IsNullOrEmpty(page)) page = "1";

            PropertyBag["Albums"] = PaginationHelper.CreatePagination(this, FavdataSource, 12);
            PropertyBag["cPage"] = page;
        }

        public void delMyAlbum(string ID,string toPage) {
            Pic_Album album = Pic_Album.Find(int.Parse(ID));
            Pic_Member currMember = (Pic_Member)Session["Member"];
            Pic_Member albumMember = album.Pic_Member;
            if (currMember.Pic_MemberID==albumMember.Pic_MemberID) {
                album.Status = 0;
                album.Update();
            }
            Redirect("/PManage/My.vk?page=" + toPage);
        }

        public void delMyFavAlbum(string ID, string toPage) {
            Pic_Favorite fav = Pic_Favorite.Find(int.Parse(ID));
            fav.Delete();
            Redirect("/PManage/MyFav.vk?page=" + toPage);
        }
    }
}